package paypal;

import java.util.HashMap;
import java.util.Map;

	public class Codec
	{
		private final static String AMPERSAND = "&";
		private final static String EQUALS = "=";
		//private final static char[] AMPERSAND_CHAR_ARRAY = AMPERSAND.toCharArray();
		//private final static char[] EQUALS_CHAR_ARRAY = EQUALS.toCharArray();
        
        private Map<String,String> urlParams = new HashMap<String,String>();
        
		public void Decode(String nvpString)
		{
			for (String nvp : nvpString.split(AMPERSAND)) {
				
				String[] tokens = nvp.split(EQUALS);
				if (tokens.length >= 2)
				{
                    getUrlParams().put(tokens[0], tokens[1]);
				}
			}
		}

		private static String GetArrayName(int index, String name)
		{
			if (index < 0)
			{
				throw new IndexOutOfBoundsException("index can not be negative : " + index);
			}
			return name + index;
		}

		public Map<String,String> getUrlParams() {
			return urlParams;
		}

		public void setUrlParams(Map<String,String> urlParams) {
			this.urlParams = urlParams;
		}
	}

